package com.airforce.mappers;

import com.airforce.model.region;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface regionMapper {
    @Delete({
        "delete from region",
        "where Id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into region (Id, Name, ",
        "ParentId, ShortName, ",
        "LevelType, CityCode, ",
        "ZipCode, MergerName, ",
        "Lng, Lat, Pinyin)",
        "values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{parentid,jdbcType=INTEGER}, #{shortname,jdbcType=VARCHAR}, ",
        "#{leveltype,jdbcType=INTEGER}, #{citycode,jdbcType=VARCHAR}, ",
        "#{zipcode,jdbcType=VARCHAR}, #{mergername,jdbcType=VARCHAR}, ",
        "#{lng,jdbcType=REAL}, #{lat,jdbcType=REAL}, #{pinyin,jdbcType=VARCHAR})"
    })
    int insert(region record);

    @InsertProvider(type=regionSqlProvider.class, method="insertSelective")
    int insertSelective(region record);

    @Select({
        "select",
        "Id, Name, ParentId, ShortName, LevelType, CityCode, ZipCode, MergerName, Lng, ",
        "Lat, Pinyin",
        "from region",
        "where Id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="Id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="Name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="ParentId", property="parentid", jdbcType=JdbcType.INTEGER),
        @Result(column="ShortName", property="shortname", jdbcType=JdbcType.VARCHAR),
        @Result(column="LevelType", property="leveltype", jdbcType=JdbcType.INTEGER),
        @Result(column="CityCode", property="citycode", jdbcType=JdbcType.VARCHAR),
        @Result(column="ZipCode", property="zipcode", jdbcType=JdbcType.VARCHAR),
        @Result(column="MergerName", property="mergername", jdbcType=JdbcType.VARCHAR),
        @Result(column="Lng", property="lng", jdbcType=JdbcType.REAL),
        @Result(column="Lat", property="lat", jdbcType=JdbcType.REAL),
        @Result(column="Pinyin", property="pinyin", jdbcType=JdbcType.VARCHAR)
    })
    region selectByPrimaryKey(Integer id);

    @UpdateProvider(type=regionSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(region record);

    @Update({
        "update region",
        "set Name = #{name,jdbcType=VARCHAR},",
          "ParentId = #{parentid,jdbcType=INTEGER},",
          "ShortName = #{shortname,jdbcType=VARCHAR},",
          "LevelType = #{leveltype,jdbcType=INTEGER},",
          "CityCode = #{citycode,jdbcType=VARCHAR},",
          "ZipCode = #{zipcode,jdbcType=VARCHAR},",
          "MergerName = #{mergername,jdbcType=VARCHAR},",
          "Lng = #{lng,jdbcType=REAL},",
          "Lat = #{lat,jdbcType=REAL},",
          "Pinyin = #{pinyin,jdbcType=VARCHAR}",
        "where Id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(region record);
    @Select("select * from region where Pinyin=#{pinyin} limit 1")
    region selectregion(String pinyin );
}